package com.snowflakes.gruntr;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;
import com.parse.ParseUser;


public class FriendAdapter extends ParseQueryAdapter<ParseObject> {

	
	public FriendAdapter(Context context) {
		// Use the QueryFactory to construct a PQA that will only show
		// Todos marked as high-pri
		super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
			public ParseQuery create() {
				
				ParseUser user = ParseUser.getCurrentUser();
				
				ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("FriendRequests");
				query.whereEqualTo("Recipient", user);
				query.whereEqualTo("Denied", "false");
				query.whereEqualTo("Accepted", "false");
				return query;
			}
		});
	}

	// Customize the layout by overriding getItemView
	@Override
	public View getItemView(ParseObject object, View v, ViewGroup parent) {
		if (v == null) {
			v = View.inflate(getContext(), R.layout.individual_request, null);
		}

		super.getItemView(object, v, parent);

		// Add the title view
		TextView titleTextView = (TextView) v.findViewById(R.id.tvReqName);
		titleTextView.setText(object.get("From").toString());
		
		Button accept = (Button) v.findViewById(R.id.bAccept);
		Button deny = (Button) v.findViewById(R.id.bDeny);
		
		accept.setTag(object.getObjectId());
		deny.setTag(object.getObjectId());
		
		return v;
	}
	
	

}

